function merge(intervals) {
    if (intervals.length <= 1) return intervals;
    // start 按第一项排序
    // 快排 时间复杂度 O(nlogn)
    intervals.sort((a, b) => a[0] - b[0]);

    const merged = [intervals[0]];

    for (let i = 1; i < intervals.length; i++) {
        const cur = intervals[i];
        const last = merged[merged.length - 1];
        if (cur[0] <= last[1]) {
            last[1] = Math.max(last[1], cur[1]);
        } else {
            merged.push(cur);
        }
    }
    return merged;
}